import os

import yaml


def write_yaml(filename, data):
    # os.getcwd() 是获取当前运行目录
    with open(os.getcwd()+"/data/"+filename, mode='a+', encoding="utf-8") as f:
        yaml.safe_dump(data, stream=f)


def read_yaml(filename, key):
    with open(os.getcwd()+"/data/"+filename, mode='r', encoding="utf-8") as f:
        data = yaml.safe_load(f)
        return data[key]


def clear_yaml(filename):
    with open(os.getcwd()+"/data/"+filename, mode='w', encoding="utf-8") as f:
        f.truncate()
